package dbDrivers;
import java.sql.*;

public class db2Connection implements dbInterface {
	private String user_name ;
    private String password ;
    static String url;
    private Connection con;
    public db2Connection() {
    	config.Config.maine();
    	user_name = config.Config.prop.getProperty("database.db2.ConnetionUser");
    	password = config.Config.prop.getProperty("database.db2.ConnectionPasswd");
    	url = "jdbc:db2://"+config.Config.prop.getProperty("database.db2.location")
        +":"+config.Config.prop.getProperty("database.db2.port")
        +"/"+config.Config.prop.getProperty("database.db2.dbName");
    	 try{ 
             Class.forName("com.ibm.db2.jcc.DB2Driver");
             System.out.println("driver loading");
         }catch(java.lang.ClassNotFoundException e){ 
             System.err.print("ClassNotFoundException:"); 
             System.err.println(e.getMessage()); 
         } 
         try{
             con = DriverManager.getConnection(url,user_name,password);
             System.out.println("baglaniyor....");
         }
         catch(Exception ex){
             System.err.println("sql hatasi: "+ ex.getMessage());
             
         }
		// TODO Auto-generated constructor stub
	}
    public boolean execute(String sql){
    	///JOptionPane.showMessageDialog(null, ex);
    	System.out.println(sql);
    	 try{
    		 boolean sonuc = con.createStatement().execute(sql);
    		 System.out.println(sonuc);
            return true;
            
         }catch(Exception e){
             System.out.println("E : "+e);
             return false;
         }
    }
    public ResultSet executeQuery(String sql){
    	try{
    		System.out.println("Sql :"+sql);
            return con.createStatement().executeQuery(sql);
            
         }catch(Exception e){
             System.out.println("E : "+e);
             return null;
         }
    }protected void finalize() {
    	try {
    		System.out.print("Db2 nesnesi kapatilir.");
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
